﻿Public Class Form1
    Dim mycustprices As New List(Of Integer)
    Dim othercustprices As New List(Of Integer)
    Dim mymoney As Integer = 0
    Dim othermoney As Integer = 0


    Private Sub otherTrack_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles otherTrack.Scroll
        'Change the price label to the new price
        OtherN.Text = "$" & otherTrack.Value
    End Sub

    Private Sub myTrack_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myTrack.Scroll
        'Change the price label to the new price
        MyN.Text = "$" & myTrack.Value
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'collect payments from custemers
        For Each cust As Integer In mycustprices
            mymoney += cust - 25
        Next
        For Each cust As Integer In othercustprices
            othermoney += cust - 25
        Next

        'update money labels
        myMonLab.Text = "$" & mymoney.ToString()
        otherMonLab.Text = "$" & othermoney.ToString()


        'add new customer
        If myTrack.Value > otherTrack.Value Then
            othercustprices.Add(otherTrack.Value)
        ElseIf otherTrack.Value > myTrack.Value Then
            mycustprices.Add(myTrack.Value)
        End If




        'some customers will swich companys
        swichCust(othercustprices, mycustprices, myTrack.Value, otherTrack.Value)


        'update customer labels
        otherC.Text = othercustprices.Count.ToString()
        myC.Text = mycustprices.Count.ToString()






    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Stop()
    End Sub




    Private Sub swichCust(ByRef other As List(Of Integer), ByRef mine As List(Of Integer), ByVal mp As Integer, ByVal op As Integer)

        'make sure both companys have more than two customers
        If other.Count < 3 Then
        ElseIf mine.Count < 3 Then
        Else


            'get random customer number
            Dim mrc As Integer = Int(((mine.Count - 1) - 0 + 1) * Rnd() + 0)
            Dim orc As Integer = Int(((other.Count - 1) - 0 + 1) * Rnd() + 0)


            'for testing
            'MessageBox.Show("Mine: " & mrc & "of" & mine.Count)
            'MessageBox.Show("Other: " & orc & "of" & other.Count)
            'Timer1.Stop()

            'figure which customer is paying more

            If mine(mrc) > other(orc) Then
                'if my customer is paying more

                'remove the customer from my company
                mine.Remove(mrc)

                'add the customer to the other company
                other.Add(op)

                mine.TrimExcess()
                other.TrimExcess()

            ElseIf other(orc) > mine(mrc) Then
                'if other customer is paying more

                'remove customer from other company
                other.Remove(orc)

                'add customer to my company
                mine.Add(mp)

                mine.TrimExcess()
                other.TrimExcess()

            End If


        End If







    End Sub








End Class